Imports System.Collections.Specialized
Imports System.net

Public Class Globals
	Public Shared IsRunning As Long = 1
	Public Shared lastData As Date
	Public Shared dbi As dbInterface = New dbInterface

	Protected Shared m_useProxy As Boolean = False
	Protected Shared m_respTimeout As Long = 60000
	Protected Shared m_connTimeout As Long = 6000
	Protected Shared m_proxyHost As String
	Protected Shared m_proxyPort As Long

	Protected Shared m_hostname As String
	Protected Shared m_port As Long
	Protected Shared m_protocol As String
	Protected Shared m_service As String
    Protected Shared m_dbconn As String = ""
    Protected Shared m_username As String = ""

	Protected Shared m_webc As WebClient
	Protected Shared m_cpci As CPCInterface

    Public Shared Property UserName() As String
        Get
            Return m_username
        End Get
        Set(ByVal value As String)
            m_username = value
        End Set
    End Property

    Public Shared Property WebClient()
        Get
            If m_webc Is Nothing Then
                m_webc = New WebClient
            End If

            Return m_webc
        End Get
        Set(ByVal Value)
            m_webc = Value
        End Set
    End Property

    Public Shared ReadOnly Property CPCInt()
        Get
            If m_cpci Is Nothing Then
                m_cpci = New CPCInterface
            End If

            Return m_cpci
        End Get
    End Property

    Public Shared Property UseProxy() As Boolean
        Get
            Return m_useProxy
        End Get
        Set(ByVal Value As Boolean)
            m_useProxy = Value
        End Set
    End Property

    Public Shared WriteOnly Property HostName() As String
        Set(ByVal Value As String)
            m_hostname = Value
        End Set
    End Property

    Public Shared WriteOnly Property Protocol() As String
        Set(ByVal Value As String)
            m_protocol = Value
        End Set
    End Property

    Public Shared WriteOnly Property Service() As String
        Set(ByVal Value As String)
            m_service = Value
        End Set
    End Property

    Public Shared WriteOnly Property Port() As Long
        Set(ByVal Value As Long)
            m_port = Value
        End Set
    End Property

    Public Shared ReadOnly Property APIUrl() As String
        Get
            If m_protocol = "" Then
                LoadXML()

                If m_protocol = "" Then

                End If
            End If

            Return m_protocol & "://" & m_hostname & "/" & m_service
            '			"https://www.marketing.services.nymex.com/cpc/cpcapi.html"
        End Get
    End Property

    Public Shared Property DBConnection() As String
        Get
            If m_dbconn = "" Then
                LoadXML()
            End If
            Return m_dbconn
        End Get
        Set(ByVal Value As String)
            m_dbconn = Value
        End Set
    End Property

    Private Shared Sub LoadXML()
        Dim xr As New XmlReader

        xr.ReadIni()
    End Sub

    Public Shared Function checkForDefault(ByVal prodid As String, ByVal field As String, ByVal ttype As String) As String
        Dim dbi As dbInterface = Globals.dbi

        Dim sql As String = "select " & ttype & "strip_def from nymx_prod_defaults where data_type='" & field & "' and prod_id='" & prodid & "'"

        dbi.query(sql)

        If dbi.eof Then
            Return ""
        End If

        Return dbi.getval(ttype & "strip_def")
    End Function

    '<http>
    '	<useProxy>false</useProxy>
    '	<responseTimeout>60000</responseTimeout>
    '	<proxyHost></proxyHost>
    '	<proxyPort></proxyPort>
    '	<connectionTimeout>6000</connectionTimeout>
    '</http>
    '<cpc>
    '	<httpapi>
    '		<server hostname="www.marketing.services.nymex.com" port="443" protocol="https" service="cpc/cpcapihtml"></server>
    '	</httpapi>
    '</cpc>

End Class

